﻿using System;
using LDE;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Media;

namespace LudumDare27
{
	internal class LD27Game : GameMain
	{
		private Random m_nextGameRand = new Random( );

		protected override void Initialize( )
		{
			base.Initialize( );

			MediaPlayer.Volume = 1.0f;

			Window.Title = "10 Second Tim - Ludum Dare 27 - Scott Bevin, scott@gameXcore.co.uk, www.gameXcore.co.uk";

			//Window.AllowUserResizing = true;

#if !SILVERLIGHT
			if ( Settings.Settings.FullScreen )
			{
				graphics.PreferredBackBufferWidth = GraphicsDevice.DisplayMode.Width;
				graphics.PreferredBackBufferHeight = GraphicsDevice.DisplayMode.Height;
				graphics.IsFullScreen = true;
			}
			else
#endif
			{
#if SILVERLIGHT
				Defs.ScreenWidth = GraphicsDevice.Viewport.Width;
				Defs.ScreenHeight = GraphicsDevice.Viewport.Height;
#endif

				graphics.PreferredBackBufferWidth = Defs.ScreenWidth;
				graphics.PreferredBackBufferHeight = Defs.ScreenHeight;
				graphics.IsFullScreen = false;
			}

			graphics.ApplyChanges( );

			GameScreensMgr.AddGameScreen( new GameScreens.IntroSplashScreen( ), null, GameScreenManager.AddGameScreenData.PositioningOptions.OnTop );

			//GameScreensMgr.AddGameScreen( new GameScreens.ChooseInputScreen( ), null, GameScreenManager.AddGameScreenData.PositioningOptions.OnTop );
		}

		public GameScreen ChooseNextGame( GameScreen current, int level )
		{
			if ( level <= 1 )
			{
				Games.Game_1.GameplayScreen.PlayedYet = false;
				Games.Game_2.GameplayScreen.PlayedYet = false;
				Games.Game_3.GameplayScreen.PlayedYet = false;
				Games.Game_4.GameplayScreen.PlayedYet = false;
				Games.Game_5.GameplayScreen.PlayedYet = false;
			}

			GameScreen chosen = null;

			do
			{
				int rnd = m_nextGameRand.Next( 100 );

				if ( rnd <= 15 && level > 4 )
				{
					chosen = new Games.GameplayIntroScreen( true, level );
				}
				else if ( rnd <= 35 )
				{
					chosen = new Games.Game_1.GameplayScreen( level );
				}
				else if ( rnd < 50 )
				{
					chosen = new Games.Game_2.GameplayScreen( level );
				}
				else if ( rnd < 65 )
				{
					chosen = new Games.Game_3.GameplayScreen( level );
				}
				else if ( rnd < 80 )
				{
					chosen = new Games.Game_4.GameplayScreen( level );
				}
				else
				{
					chosen = new Games.Game_5.GameplayScreen( level );
				}
			} while ( chosen == null || ( current != null && chosen.GetType( ) == current.GetType( ) ) );

			return chosen;
		}

		public Song PickSong( ContentManager content )
		{
			return content.Load<Song>( "Music/S" + m_nextGameRand.Next( 1, 6 ).ToString( ) );
		}
	}
}